﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


namespace 学生成绩查询及选课系统.teacher
{
    public partial class alterScore : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
               Label1.Text= Request.QueryString["stuno"].ToString();
               Label2.Text = Request.QueryString["cno"].ToString();
               string sql = "select * from grade where stuno=@stuno and cno=@cno ";
               SqlParameter[] sqlarray = { new SqlParameter("@stuno", Label1.Text), new SqlParameter("@cno", Label2.Text) };
               SqlDataReader sdr=DBAccess.GetReader(sql,sqlarray);
               if (sdr.Read()==true)
               {
                   TextBox3.Text = sdr["score"].ToString();
                   TextBox4.Text = sdr["status"].ToString();
               }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string score = TextBox3.Text;
            string status = TextBox4.Text;
            string update_sql = "UPDATE grade SET score=@score,status=@status WHERE stuno=@stuno and cno=@cno ";
            SqlParameter[] arr1 = { new SqlParameter("@score", score), new SqlParameter("@status", status), new SqlParameter("@stuno", Label1.Text), new SqlParameter("@cno", Label2.Text) };

            try
            {
                int count = DBAccess.GetState(update_sql,arr1);
                if (count !=0)
                {
                    Response.Write("<script>alert('修改成功！');setTimeout(window.location.href ='studentScore.aspx' , 3); </script>");
                }
                else
                {
                    Label3.Text = "修改失败！";
                }
            }
            catch (Exception)
            {
                Label3.Text = "修改失败！";

            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("./studentScore.aspx");
        }
    }
}